package com.weixinli.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import com.weixinli.beans.Article;
import com.weixinli.beans.PageInfo;
import com.weixinli.dao.IArticleDao;

@Repository("iArticleDao")
public class ArticleDaoImpl implements IArticleDao {

	@Resource(name="sqlSession")
	private SqlSession sqlSession;
	
	public List<Article> findAll(String atype) {
		return sqlSession.selectList("articleDao.findAll", atype);
	}

	public int addArticle(Article at) {
		return sqlSession.insert("articleDao.addArticle", at);
	}

	public int delArticle(Article article) {
		return sqlSession.delete("articleDao.delArticle", article);
	}

	public int modArticle(Article at) {
		return 0;
	}

	public int getTotalArticle() {
		return sqlSession.selectOne("articleDao.totalArticle");
	}

	public List<Article> getIndexArticle() {
		return sqlSession.selectList("articleDao.getIndexArticle");
	}
	public Article getOneArticle(String aid) {
		return null;
	}
	public Article getOneArticle(Article at) {
		return sqlSession.selectOne("articleDao.getOneArticle", at);
	}

	public List<Article> getTypeArticle(String atype) {
		return null;
	}

	public List<Article> getAllArtcle(Integer num) {
		return null;
	}

	public void setSqlSession(SqlSession sqlSession) {
		this.sqlSession = sqlSession;
	}

	public List<Article> findPage(Integer pageNo, Integer pageSize) {
		Map<String,Object> map=new HashMap<String, Object>();
		map.put("pageNo", (pageNo-1)*pageSize);
		map.put("pageSize", pageSize);
		return sqlSession.selectList("articleDao.findPage", map);
	}
}
